<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas画笔效果</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        html,body,#app{
            width:100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div id="app">
        <canvas id="canvas"></canvas>
    </div>
    <script>
        app.addEventListener('touchstart', function(e){
            e.preventDefault();
        });

        //获取元素
        let canvas = document.querySelector('#canvas');
        //设置宽高
        canvas.width = document.documentElement.clientWidth;
        canvas.height = document.documentElement.clientHeight;

        //创建画笔对象
        let ctx = canvas.getContext('2d');
        
        //触摸开始
        canvas.addEventListener('touchstart', function(e){
            //移动画笔  move 移动 to 
            // ctx.strokeStyle = 'red';
            // ctx.lineWidth = 20;
            ctx.moveTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
        });

        //触摸移动
        canvas.addEventListener('touchmove', function(e){
            //画线
            ctx.lineTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
            //描边
            ctx.stroke();
        });
    </script>
</body>
</html>